"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from selenium.webdriver.common.by import By

from web_auto_testing.page.base_page import BasePage


class PostingPage(BasePage):

    _CREATE_TOPIC = (By.ID, "create-topic")
    _REPLY_TITLE = (By.ID, "reply-title")
    _SELECT_CATEGORY = (By.CSS_SELECTOR, "summary[name^='筛选条件：类别']")
    _POLITE_RADIO = (By.CSS_SELECTOR, ".select-kit-collection>li:nth-child(1)")
    _INPUT_TEXT = (By.CSS_SELECTOR, "textarea[aria-label^='在此处输入']")
    _BUTTON_CREATE = (By.XPATH, "//span[text()='创建话题']")
    _TEXT_TITLE = (By.CSS_SELECTOR, ".fancy-title")

    def posting_text(self, input_title, input_text):
        """
        论坛发帖
        :param input_title:
        :param input_text:
        :return:
        """
        # 点击论坛发帖
        self.do_click(self._CREATE_TOPIC)
        # 输入标题
        self.do_send_keys(input_title, self._REPLY_TITLE)
        # 点击类别下拉列表,选择节点
        self.do_click(self._SELECT_CATEGORY)
        self.do_click(self._POLITE_RADIO)
        # 内容输入框输入帖子内容
        self.do_send_keys(input_text, self._INPUT_TEXT)
        # 点击创建话题
        self.do_click(self._BUTTON_CREATE)
        # 返回成功后的标题内容
        return self.do_find(self._TEXT_TITLE).text
